<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/12/05 22:12:34 $)
// $RCSfile: report_adtracking.php,v $ : $Revision: 1.1 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

$template->assign("calendar", true);

$interface->staffHeader($_SWIFT["language"]["livesupport"]." &gt; ".$_SWIFT["language"]["adtrackingreport"], 3);

$interface->staffNavBar('<a href="index.php?_m=livesupport&_a=adtracking" title="'.$_SWIFT["language"]["managecampaigns"].'">'.$_SWIFT["language"]["managecampaigns"].'</a> &raquo; '.'<a href="index.php?_m=tickets&_a=adreports" title="'.$_SWIFT["language"]["adtrackingreport"].'">'.$_SWIFT["language"]["adtrackingreport"].'</a>', "", 3);

printInfoBox($infomessage);
printErrorBox($errormessage);

?><!--
<form name="swiftform" action="index.php" method="POST">

<fieldset class="swiftfieldset">
<legend><?=$_SWIFT["language"]["filter"]?></legend>
<table width="100%"  border="0" cellspacing="1" cellpadding="2" class="tborder">
<tr>
<?
if (empty($_POST["datefrom"]) && empty($_POST["dateto"]))
{
	$_prevday = DATENOW-86400;
	$_gdatefrom = date("d/m/Y", $_prevday);
	$_gdateto = date("d/m/Y", DATENOW);
} else {
	$_gdatefrom = $_POST["datefrom"];
	$_gdateto = $_POST["dateto"];
}

?>
<td width="100" class="row1" nowrap><?=$_SWIFT["language"]["fildate"]?></td>
<td class="row2"><input type="text" name="datefrom" id="datefrom" size="12" readonly="1" value="<?=iif(!empty($_gdatefrom), $_gdatefrom)?>" class="swifttext" onclick="return showCalendar('datefrom', '%d/%m/%Y');" />&nbsp;<img src="<?=$_SWIFT["themepath"]?>calendar.gif" id="datefromtrigger" style="cursor: pointer;" align="absmiddle" onclick="return showCalendar('datefrom', '%d/%m/%Y');" /> <?=$_SWIFT["language"]["filto"]?> <input type="text" name="dateto" id="dateto" size="12" readonly="1" value="<?=iif(!empty($_gdateto), $_gdateto)?>" class="swifttext" onclick="return showCalendar('dateto', '%d/%m/%Y');" />&nbsp;<img src="<?=$_SWIFT["themepath"]?>calendar.gif" id="datetotrigger" style="cursor: pointer;" align="absmiddle" onclick="return showCalendar('dateto', '%d/%m/%Y');" /></td>
<td width="100" class="row2" align="right" nowrap><input type="submit" class="yellowbutton" name="filter" value="<?=$_SWIFT["language"]["filter"]?>"></td>
</tr>
</table>
</fieldset><BR />
<input type="hidden" name="_m" value="livesupport"><input type="hidden" name="_a" value="adreports">
</form>-->
<?
$_datefrom = getCalendarDateline($_gdatefrom);
$_dateto = getCalendarDateline($_gdateto);
$_dateto = mktime(23,59,59,date("m", $_dateto), date("d", $_dateto), date("Y", $_dateto));

$_campaigns = $_campaignidlist = array();
$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."adcampaigns` ORDER BY `campaignid` ASC;");
while ($dbCore->nextRecord())
{
	$_campaigns[$dbCore->Record["campaignid"]] = $dbCore->Record;
	$_campaignidlist[] = $dbCore->Record["campaignid"];
}

// ======= REFERRERS =======
$_top15ref = $_recent30ref = array();
$dbCore->query("SELECT `referrer`, COUNT(*) AS totalhits FROM `". TABLE_PREFIX ."adhitlogs` WHERE `campaignid` IN (". buildIN($_campaignidlist) .") GROUP BY `referrer` ORDER BY totalhits DESC LIMIT 15;");
while ($dbCore->nextRecord())
{
	$_top15ref[] = $dbCore->Record;
}

$dbCore->query("SELECT `referrer`, dateline FROM `". TABLE_PREFIX ."adhitlogs` WHERE `campaignid` IN (". buildIN($_campaignidlist) .") ORDER BY campaignid DESC LIMIT 30;");
while ($dbCore->nextRecord())
{
	$_recent30ref[] = $dbCore->Record;
}
?>
<fieldset class="swiftfieldset"><legend><?=$_SWIFT["language"]["top15ref"]?></legend>
<table width="100%"  border="0" cellspacing="1" cellpadding="3" class="tborder">

<tr class="tabletitlerow">
<td width="">&nbsp;<?=$_SWIFT["language"]["referrer"]?></td>
<td width="100">&nbsp;<?=$_SWIFT["language"]["hits"]?></td>
</tr>
<?
foreach ($_top15ref as $key=>$val)
{
	?>
	<tr class="<?=getRowBG();?>">
	<td>&nbsp;<?=htmlspecialchars($val["referrer"])?></td>
	<td>&nbsp;<?=intval($val["totalhits"])?></td>
	</tr>
	<?
}
?>
</table></fieldset>
<?

$template->assign("backurl", "index.php?_m=livesupport&_a=adtracking");

$interface->staffFooter();
?>